//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    height: app.globalData.height,
    width: app.globalData.width,
    barHeight: app.globalData.barHeight,
    serverUrl: app.globalData.serverUrl,
    uid: wx.getStorageSync('uid'),
    item: [],
  },
  //事件处理函数
  onLoad(options) {
    this.setData({
      item: JSON.parse(options.item)
    })
  },
  //返回
  back: function(e) {
    wx.navigateBack({
      delta: 1,
    })
  },
  copyp(e) {
    wx.setClipboardData({
      data: this.data.item.phone,
      success: function(res) {
        wx.showToast({
          title: '已复制',
          icon: "none",
          duration: 800,
        })
      },
      fail: function(res) {
        wx.showToast({
          title: '抱歉，复制失败！',
          icon: "none",
          duration: 800,
        })
      }
    })
  },

  copyw(e) {
    wx.setClipboardData({
      data: this.data.item.weChat,
      success: function(res) {
        wx.showToast({
          title: '已复制',
          icon: "none",
          duration: 800,
        })
      },
      fail: function(res) {
        wx.showToast({
          title: '抱歉，复制失败！',
          icon: "none",
          duration: 800,
        })
      }
    })
  },
  done(e) {
    var that = this;
    wx.showModal({
      title: '确认完成？',
      content: '完成后将隐藏个人信息',
      success(res) {
        if(res.confirm){
          wx.request({
            url: app.globalData.serverUrl + '/admin/express/doneexpress',
            method: 'POST',
            data: {
              token: wx.getStorageSync('token'),
              id: that.data.item.id
            },
            success(res) {
              if (res.data.code == 1) {
                wx.showToast({
                  title: '确认成功',
                  icon: "success",
                  duration: 800,
                })
                // wx.redirectTo({
                //   url: '/pages/express/express',
                // })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.showToast({
                  title: '确认失败',
                  icon: "fali",
                  duration: 800,
                })
              }
            }
          })
        }
      }
    })
  },

  del(e) {
    var that = this;
    wx.showModal({
      title: '确认删除?',
      content: '删除后将不可恢复',
      confirmColor: '#f7635b',
      success(res) {
        if(res.confirm){
          wx.request({
            url: app.globalData.serverUrl + '/admin/express/delexpress',
            method: 'POST',
            data: {
              token: wx.getStorageSync('token'),
              id: that.data.item.id
            },
            success(res) {
              if (res.data.code == 1) {
                wx.showToast({
                  title: '删除成功',
                  icon: "success",
                  duration: 800,
                })
                wx.redirectTo({
                  url: '/pages/express/express',
                })
              } else {
                wx.showToast({
                  title: '删除失败',
                  icon: "fali",
                  duration: 800,
                })
              }
            }
          })
        }
      }
    })
  }

})